package com.ouc.openplatform.utils;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;

public class ListCopy {
	/**
	 * 将model集合转化为DTO集合
	 * @param fList  model集合
	 * @param clazz  DTO类型
	 * @return
	 */
	public static <F, T> List<T> convertFor(List<F> fList, Class<T> clazz) {
		List<T> tList = new ArrayList<T>();
		try {
			for (F f : fList) {
				T t = clazz.newInstance();
				BeanUtils.copyProperties(t, f);
				tList.add(t);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return tList;
	}
	
	
	public static void main(String[] args) {
//		List<EUTreeNode> EUTreeNodeList=new ArrayList<EUTreeNode>();
//		for (int i = 0; i < 3; i++) {
//			EUTreeNode e=new EUTreeNode();
//			e.setId(i);
//			e.setText("----");
//			e.setState("open");
//			EUTreeNodeList.add(e);
//		}
//		List<EUTreeNodeDTO> EUTreeNodeDTOList=ListCopy.convertFor(EUTreeNodeList, EUTreeNodeDTO.class);
//		for (EUTreeNodeDTO euTreeNodeDTO : EUTreeNodeDTOList) {
//			System.out.println(euTreeNodeDTO.toString());
//		}
		
	}

}



